package com.xm.xmapp.http;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.HttpHeaderParser;

public class VolleyHttpUpLoad extends Request<String> {

	public Listener<String> listener;
	private Map<String, String> map;

	public VolleyHttpUpLoad(int method, String url, Map<String, String> map, Listener<String> listener,
			GetDataErrorListener errorListener) {
		super(method, url, errorListener);
		this.listener = listener;
		this.map = map;

	}

	@Override
	protected Map<String, String> getParams() throws AuthFailureError {
		return map;
	}

	@Override
	protected void deliverResponse(String response) {
			listener.onResponse(response);		
	}

	@Override
	protected Response<String> parseNetworkResponse(NetworkResponse response) {
		String str = null;
		try {
			str = new String(response.data, "utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return Response.success(str, HttpHeaderParser.parseCacheHeaders(response));
	}

}
